package com.example.service;

import com.example.entity.PetCheckUpInfo;
import com.example.mapper.PetCheckUpInfoMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author HY
 * @date 2025/2/18
 */
@Service
public class PetCheckUpInfoService {
    @Autowired
    private PetCheckUpInfoMapper petCheckUpInfoMapper;
    public PageInfo<PetCheckUpInfo> listPage(Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        Integer userId = TokenUtils.getCurrentUser().getId();
        return PageInfo.of(petCheckUpInfoMapper.selectListByUserId(userId));
    }

    public List<PetCheckUpInfo> list(Integer userId) {
        return petCheckUpInfoMapper.selectListByUserId(userId);
    }

    public void save(PetCheckUpInfo petCheckUpInfo) {
        petCheckUpInfo.setUserId(TokenUtils.getCurrentUser().getId());
        petCheckUpInfoMapper.insert(petCheckUpInfo);
    }

    public void delete(Integer id) {
        petCheckUpInfoMapper.deleteById(id);
    }
}
